namespace egret.socketio.engine {

    export enum _emPacketType {
        open = 0,
        close,
        ping,
        pong,
        message,
        upgrade,
        noop,
        error
    }

    export class TransportUri extends Uri {
        timestampRequests?: boolean;
        timestampParam?: string;
        hostname?: string;
        socket?: Socket;
        secure?: boolean;
        policyPort?: number;

        constructor(str?: string) {
            super(str);
            this.secure = /^(http|ws)s$/.test(this.protocol);
            this.timestampParam = 't';

            let hostname = this.host;
            if (this.ipv6) {
                let start = hostname.indexOf('[');
                if (start != -1)
                    hostname = hostname.substring(start + 1);
                let end = hostname.lastIndexOf(']');
                if (end != -1)
                    hostname = hostname.substring(0, end);
            }
            this.hostname = hostname;
        }

        get ipv6(): boolean {
            return this.host.split(":").length > 2;
        }

        clone(): TransportUri {
            return new TransportUri(this.toString());
        }
    }

    export class SocketUri extends TransportUri {
        transports?: Array<any>;
        upgrade?: boolean = true;
        rememberUpgrade?: boolean;
        transportOptions?: { [name: string]: TransportUri };

        constructor(str?: string) {
            super(str);
            this.transportOptions = {};
        }

        clone(): SocketUri {
            return new SocketUri(this.toString());
        }
    }

    export interface Packet {
        type: string;
        data?: any;
        options?: any;
    }
}